package com.wcr.edu.info.manager.controller;

import com.wcr.edu.info.manager.domain.Teacher;
import com.wcr.edu.info.manager.service.TeacherService;

import java.util.Scanner;

public class TeacherController {

    TeacherService teacherService = new TeacherService();
    Scanner sc = new Scanner(System.in);

    public void teacherstart() {


        //系统菜单搭建

            abc:
            while (true) {
                System.out.println("--------欢迎来到 <老师> 管理系统--------");
                System.out.println("请输入您的选择: 1.添加老师  2.删除老师  3.修改老师  4.查看老师  5.退出");
                String choice = sc.next();
                switch (choice) {
                    case "1":
                        //System.out.println("添加老师");
                        addTeacher();
                        break;
                    case "2":
                        //System.out.println("删除老师");
                        deleteTeacher();

                        break;
                    case "3":
                        xiuGaiTeacher();
                        //System.out.println("修改老师");
                        break;
                    case "4":
                        ckTeacher();
                        //System.out.println("查看老师");
                        break;
                    case "5":
                        System.out.println("感谢您的使用,谢谢");
                        break abc;
                    default:
                        System.out.println("您的输入有误,请重新输入");
                        break;

                }
            }
        }

        //删除老师方法(客服)
        private void deleteTeacher() {
            Teacher[] stu = teacherService.ckTeacher();
            if (stu == null) {
                System.out.println("暂无存储信息,请添加后重试");
                return;
            }
            System.out.println("请输入您要删除的老师ID");
            String shanChuId = sc.next();

            boolean is = teacherService.isId(shanChuId);
            if (is) {
                teacherService.shanChuId(shanChuId);
                System.out.println("删除成功");

            } else {
                System.out.println("ID不存在,删除失败");
            }
        }

        //修改老师方法(客服)
        private void xiuGaiTeacher() {
            Teacher[] stu = teacherService.ckTeacher();
            if (stu == null) {
                System.out.println("暂无存储信息,请添加后重试");
                return;
            }

            System.out.println("请输入您要修改的ID");
            String newid = sc.next();
            boolean isid = teacherService.isId(newid);
            if (isid) {
                Teacher newteacher = getTeacher(newid);
                boolean s = teacherService.xiugai(newid, newteacher);
                if (s) {
                    System.out.println("恭喜,修改成功");

                }
            } else {
                System.out.println("您输入的id不存在");

            }

        }


        //  添加老师方法(客服)
        private void addTeacher() {
            String sid;

            //键盘录入老师信息
            while (true) {
                System.out.println("请输入老师工学号");
                sid = sc.next();
                //输入id,检查是否重复
                boolean is = teacherService.isId(sid);
                if (!is) {
                    break;
                } else {
                    System.out.println("您输入的工号已被占用,请重新输入");
                }
            }
            //不重复的话,输入姓名 年龄 生日
            Teacher student = getTeacher(sid);
            //将信息传入到业务员
            //调用业务员的添加方法
            boolean add = teacherService.addS(student);
            //如果为true,则题是添加成功
            if (add) {
                System.out.println("恭喜您,添加成功");
            } else {
                System.out.println("添加失败,请检查");
            }
        }

        //添加老师信息方法(客服)
        public Teacher getTeacher(String sid) {
            System.out.println("请输入老师姓名");
            String sname = sc.next();
            System.out.println("请输入老师年龄");
            String sage = sc.next();
            System.out.println("请输入老师生日");
            String sbirthday = sc.next();
            //创建一个老师类对象 用来接收存放数据
            Teacher teacher = new Teacher();
            teacher.setId(sid);
            teacher.setName(sname);
            teacher.setAge(sage);
            teacher.setBirthday(sbirthday);
            return teacher;
        }


        //查看老师方法(客服)
        private void ckTeacher() {

            Teacher[] stu = teacherService.ckTeacher();
            if (stu == null) {
                System.out.println("暂无存储信息,请添加后重试");
                return;
            }

            System.out.println("工号\t\t姓名\t年龄\t生日");
            for (int i = 0; i < stu.length; i++) {
                Teacher s1 = stu[i];
                if (s1 != null) {
                    System.out.println(s1.getId() + "\t" + s1.getName() + "\t" + s1.getAge() + "\t\t" + s1.getBirthday());
                }

            }

        }
    }




